This repository was archived by the owner on May 21, 2026. It is now read-only.
fix: populate tool_calls in conversation history for streamEvents - #98
Open
clawtom wants to merge 1 commit into
Open
fix: populate tool_calls in conversation history for streamEvents#98clawtom wants to merge 1 commit into
clawtom wants to merge 1 commit into
Conversation
When streamEvents() saves the final AI response to conversation history, it created an AIMessage with only the text content. Any tool calls made during execution were discarded, causing getConversationHistory() to return AIMessages with an empty tool_calls array. Fix: track tool calls from on_tool_start events as the agent runs, then pass them to the AIMessage constructor when saving to history. The on_tool_start event provides the tool name, input args, and run_id (used as the call id) in a provider-agnostic way. Fixes mcp-use#8 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
streamEvents()with memory enabled,getConversationHistory()returnsAIMessageobjects with an emptytool_callsarray, even when the agent used tools during execution (fixes #8).The issue is in how conversation history is saved at the end of
streamEvents():The
AIMessagereceives only the text response. Tool call data is available throughout execution but never propagated to the history entry.Fix
Track tool calls from
on_tool_startevents as the agent runs. These events are emitted by LangChain for every tool invocation and provide the tool name, input args, and run ID in a provider-agnostic way (works with ChatBedrockConverse, ChatOpenAI, ChatAnthropic, etc.).When saving to history, pass the accumulated tool calls to the
AIMessageconstructor:Changes